
import { createRouter, createWebHistory } from 'vue-router'
import Home from "../views/home/index.vue";

const routes = [
  {
    path: "/",
    name: 'Home',
    meta: { unAuth: true },
    redirect: '/local',
    component: Home,
    children: [
      //本地音乐
      {
        path: "local",
        meta: { unAuth: true },
        name: "Local",
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/local/index.vue"),
      },
      //我的歌单
      {
        path:'musiclist/:type',
        name:'Likes',
        component: () => import("../views/likes/index.vue")
      },
      //创建歌单
      {
        path: 'createMusicList',
        name: 'CreateMusicList',
        component: () => import("../views/createmusiclist/index.vue")
      },
      //播放历史
      {
        path:'history',
        name:'History',
        component:()=>import("../views/history/index.vue")
      },
      //评论区
      {
        path:'topic/:id',
        name:'Topic',
        component:()=>import("../views/topic/index.vue")
      },
      //设置
      {
        path:'settings',
        name:'Settings',
        component:()=>import("../views/settings/index.vue")
      }
    ]
  }
];
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

//全局路由守卫获取用户信息
// router.beforeEach((to, from, next) => {
//   if (localStorage.token) {
//     if (!to.meta.unAuth) {
//     //   axios.defaults.headers.token = localStorage.token;
//     //   axios.get('/users/usermessage').then(res => {
//     //     store.commit('setUserMessage', res.data);
//         next();
//       }).catch(err => {
//         next();
//       })
//     } else {
//       axios.defaults.headers.token = localStorage.token;
//       axios.get('/users/usermessage').then(res => {
//         store.commit('setUserMessage', res.data);
//       }).catch(err => {

//       })
//       next();
//     }
//   }else{
//     next();
//   }


// })

export default router;
